<template>


<el-row>
	<el-col :span="12" :offset="6">
		<!-- 测试专用 -->
		<el-card class="box-card">
			<template #header>
				<div class="card-header">
					<span>测试专用功能 - 清空数据库并导入测试专用数据</span>
				</div>
			</template>
			<el-button type="primary" @click="make_test_data">清空数据库并创建测试数据</el-button>
		</el-card>

		<!-- 大类数据和小类数据恢复 -->
		<el-card class="box-card">
			<template #header>
				<div class="card-header">
					<span>大类数据和小类数据恢复</span>
				</div>
			</template>
			<el-form-item>
				<el-button type="primary" @click="make_big_from_small()">重建大类数据</el-button>
				<el-button type="primary" @click="make_small_from_record()">重建小类数据</el-button>
			</el-form-item>
		</el-card>

		<!-- 数据导入导出 -->
		<el-card class="box-card">
			<template #header>
				<div class="card-header">
					<span>数据库导出功能 - 以不同形式导出数据 开发中……</span>
				</div>
			</template>
			<el-button type="primary">以SQL形式导出</el-button>
			<el-button type="primary">以postgresql形式导出</el-button>
		</el-card>

		<!-- 历史数据删除 -->
		<el-card class="box-card">
			<template #header>
				<div class="card-header">
					<span>历史数据删除 - 将所选时间点之前的记录删除，并保留信息 开发中……</span>
				</div>
			</template>
			<el-form :model="history_data_delete_form" label-width="90px">
				<el-form-item label="时间点选择">
					<el-col :span="10">
						<el-date-picker
							v-model="history_data_delete_form.date"
							type="Date"
							placeholder="选择日期"
							style="width: 100%"
						/>
					</el-col>
					<el-col :span="1" class="text-center">
						<span class="text-gray-500">-</span>
					</el-col>
					<el-col :span="10">
						<el-time-picker
							v-model="history_data_delete_form.time"
							placeholder="选择时间"
							style="width: 100%"
						/>
					</el-col>
				</el-form-item>
			</el-form>
			<el-form-item>
				<el-button type="primary" @click="history_data_delete">执行</el-button>
			</el-form-item>
		</el-card>

		<!-- 对长期未使用的零件进行关闭 -->
		<el-card class="box-card">
			<template #header>
				<div class="card-header">
					<span>统一关闭长期未使用的小类零件 开发中……</span>
				</div>
			</template>
			<el-form :model="long_time_not_use" label-width="90px" :inline="true">
				<el-form-item label="日期间隔">
					<el-input v-model="long_time_not_use.gap" />
				</el-form-item>
				<el-form-item label="选择小类">
					<el-input v-model="long_time_not_use.small_id" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="long_time_not_use_func">执行</el-button>
				</el-form-item>
			</el-form>
		</el-card>

		<!-- 数据库合法性检查并纠正 -->
		<el-card class="box-card">
			<template #header>
				<div class="card-header">
					<span>数据库合法性检查 开发中……</span>
				</div>
			</template>
<!--			<el-form-item>-->
<!--				<el-button type="primary" @click="legality_check">执行合法性检查</el-button>-->
<!--				<el-button type="primary" @click="fixed_bugs">修正错误</el-button>-->
<!--			</el-form-item>-->
		</el-card>

	</el-col>
</el-row>

</template>

<script setup lang="ts">
import {reactive} from "vue";
import {reqMakeBigData, reqMakeTestData} from "@/api/first/SetUp/index.js";
import {ElMessage} from "element-plus";
import {TestDataMakeResponse} from "@/api/first/SetUp/type.js";

// 创建测试数据
const make_test_data = () => {
	reqMakeTestData({
	}).then((res: TestDataMakeResponse)=>{
		ElMessage.success(res.success?.message)
	})
}


// 历史数据删除功能
const history_data_delete_form = reactive({
	date: '',
	time: '',
})
const history_data_delete = () => {

}

// 对长期未使用的小类零件进行关闭
const long_time_not_use = reactive({
	gap: '50',
	small_id: ''
})
const long_time_not_use_func = () => {

}

// 数据库合法性检查
const make_big_from_small = async () => {
	await reqMakeBigData({})
	ElMessage.success('大类总数恢复完成')
}

// 自动修正错误
const make_small_from_record = () => {
	ElMessage.info('开发中')
}



</script>

<style scoped>
.card-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.box-card {
	margin-top: 20px;
}
</style>